/*
** utils_symList.c for utils_symList in /home/vermel/local/epitech/tek2/c/ftrace/pullup-project/sources
** 
** Made by nathan vermelle
** Login   <vermel_n@epitech.net>
** 
** Started on  Sun Jul  1 17:40:46 2012 nathan vermelle
** Last update Sun Jul  1 17:42:02 2012 nathan vermelle
*/

#include <elf.h>
#include "../includes/elf.h"

static char	*forbid[11] =
  {
    ".note",
    ".rodata",
    ".eh_frame",
    ".comment",
    ".dynstr",
    ".dynsym",
    ".line",
    ".rel",
    ".shstrtab",
    ".symtab",
    ".plt"
  };

int	checkSymType(Elf64_Sym *sym, t_utils_elf *e)
{
  int   cpt;

  if (sym->st_shndx == SHN_ABS || sym->st_shndx == SHN_COMMON
      || sym->st_shndx == SHN_UNDEF)
    return (0);
  cpt = 0;
  while (cpt < 11)
    {
      if (!strcmp(forbid[cpt], e->strtab + e->sectab[sym->st_shndx].sh_name))
        return (-1);
      ++cpt;
    }
  return (0);
}

int	isNokSym(Elf64_Sym *sym, t_utils_elf *e)
{
  if (checkSymType(sym, e) ||
      sym->st_info == STT_FILE || !e->strsymtab[sym->st_name] ||
      !(ELF64_ST_TYPE(sym->st_info) == (STT_NOTYPE) ||
	ELF64_ST_TYPE(sym->st_info) == (STT_FUNC) ||
	ELF64_ST_TYPE(sym->st_info) == (STT_GNU_IFUNC)))
    return (-1);
  return (0);
}

char	*getSym(t_symList *sl, unsigned long addr)
{
  while (sl)
    {
      if (sl->addr == addr)
	return (sl->str);
      sl = sl->next;
    }
  return (NULL);
}
